﻿using System.Collections.Generic;
using Algoritmia.Schemes;

namespace Algoritmia.Problems.ExactCover
{
    public class ExactCoverDLX1Solver
    {
        private readonly BacktrackingEnumerator<DLX.State, DLX.Cell, IEnumerable<int>> _solver;

        public ExactCoverDLX1Solver()
        {
            _solver =
                new BacktrackingEnumerator
                    <DLX.State, DLX.Cell,
                        IEnumerable<int>>(createSolution: (space, i, decisions, f) => f.Selected);
        }

        public IEnumerable<int> Solve(IEnumerable<IEnumerable<int>> ones)
        {
            return _solver.First(new DLX1StateSpace(ones));
        }
    }

}
